package com.huitone.gddw.service.impl.business;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.huitone.gddw.dao.business.IRecvSmDao;
import com.huitone.gddw.dao.entity.RecvSm;
import com.huitone.gddw.model.support.QueryPage;
import com.huitone.gddw.service.business.IRecvSmService;
import com.huitone.gddw.service.dto.business.RecvSmDTO;
import com.huitone.gddw.service.system.IRoleService;
import com.huitone.gddw.utils.SysLoginUtil;

/**
 * 短信接收记录 接口实现类
 * @author wuluodan
 *
 */
@Service
public class RecvSmService implements IRecvSmService {

	@Autowired
	private IRecvSmDao recvSmDao;
	
	@Autowired
	private IRoleService roleService;
	
	@Override
	public QueryPage<RecvSmDTO> selectPage(QueryPage<RecvSm> page) {
		List<RecvSmDTO> result = null;
		int totalCount = 0;
		
		Map<String, Object> map = new HashMap<String, Object>();
		map.put("svrNode", page.getParams().get("svrNode"));
		map.put("userNo", page.getParams().get("userNo"));
		map.put("startDate", page.getParams().get("startDate"));
		map.put("endDate", page.getParams().get("endDate"));
		map.put("userId", SysLoginUtil.getLoginUserId());
		map.put("start", (page.getPageNo() - 1) * page.getPageSize() + 1);
		map.put("end", page.getPageNo() * page.getPageSize());
		
		if (roleService.isRootAcsFlag(SysLoginUtil.getLoginUserId())) {
			result = recvSmDao.selectRoot(map);
			totalCount = recvSmDao.countRoot(map);
		} else {
			result = recvSmDao.selectUnit(map);
			totalCount = recvSmDao.countUnit(map);
		}
		
		QueryPage<RecvSmDTO> queryPage = new QueryPage<RecvSmDTO>();
		queryPage.setResult(result);
		queryPage.setPageNo(page.getPageNo());
		queryPage.setPageSize(page.getPageSize());
		queryPage.setTotalCount(totalCount);
		return queryPage;
	}

	@Override
	public RecvSmDTO getDetial(String recId) {
		return recvSmDao.selectByPrimaryKey(recId);
	}

	@Override
	public List<RecvSmDTO> getRecord(Map<String, Object> params) {
		if (roleService.isRootAcsFlag(SysLoginUtil.getLoginUserId())) {
			return recvSmDao.getRecordRoot(params);
		}
		params.put("userId", SysLoginUtil.getLoginUserId());
		return recvSmDao.getRecordUnit(params);
	}

}
